package com.ujiuye.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ujiuye.config.PageResult;
import com.ujiuye.config.QueryPageBean;
import com.ujiuye.config.Result;
import com.ujiuye.mapper.CheckitemMapper;
import com.ujiuye.pojo.Checkitem;
import com.ujiuye.service.ICheckitemService;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 检查项 服务实现类
 * </p>
 *
 * @author zs
 * @since 2021-07-05
 */
@Service
public class CheckitemServiceImpl extends ServiceImpl<CheckitemMapper, Checkitem> implements ICheckitemService {
    @Resource
    private CheckitemMapper checkitemMapper;

    @Override
    public PageResult listPage(QueryPageBean queryPageBean) {
        //获取分页对象
        Page<Checkitem> page = new Page<>(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //获取到查询条件
        String queryString = queryPageBean.getQueryString();
        //创建条件构造对象
        QueryWrapper<Checkitem> queryWrapper = new QueryWrapper();
          //判断查询条件是否为空
        if (queryString!=null && queryString.length()>0){
            //不为空构造条件
            queryWrapper.eq("code",queryString).or().eq("name",queryString);
        }
        //进行查询返回一个分页对象
        Page<Checkitem> checkitemPage = checkitemMapper.selectPage(page, queryWrapper);
        //将分页对象里数据取出放入封装好的工具类中
        PageResult pageResult = new PageResult(checkitemPage.getTotal(),checkitemPage.getRecords());


        return pageResult;
    }
}
